import { Inject, Injectable } from '@nestjs/common';
import { count } from 'drizzle-orm';
import { MySql2Database } from 'drizzle-orm/mysql2';

import { DRIZZLE_CONNECTION } from '@database/constants/database.constants';
import { userRole } from '@database/schema';

@Injectable()
export class UserRolesRepository {
  constructor(
    @Inject(DRIZZLE_CONNECTION)
    private readonly db: MySql2Database,
  ) {}

  async count(): Promise<number> {
    const query = await this.db.select({ count: count() }).from(userRole);

    return query[0].count;
  }
}
